<template>
  <div class="app-container">
    <!-- 添加或修改工单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="680" append-to-body v-drag-fullscreen>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="form-flex">
        <el-row :gutter="20">
          <el-col :span="8" :xs="24">
            <el-form-item label="所属小区">{{form.communityName}} </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="工单类型">{{form.orderTypeName}} </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="发起人">{{form.charterMemberName}} </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="发起时间">{{form.charterTime}} </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="服务区域"> {{dict.label.coverage[form.coverage]}} </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="重要程度"> {{dict.label.degree_importance[form.degreeImportance]}} </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="反映人"> {{form.reflectPeople}} </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="手机号码"> {{form.phoneNum}} </el-form-item>
          </el-col>
          <el-col :span="24" :xs="24">
            <el-form-item label="所在位置">{{form.location}} </el-form-item>
          </el-col>
          <el-col :span="24" :xs="24">
            <el-form-item label="内容描述">
              <el-input
                type="textarea"
                readonly
                :autosize="{ minRows: 2, maxRows: 4}"
                v-model="form.content">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="办结人" prop="concludePersonName">
              <el-input v-model="form.concludePersonName"  placeholder="请选择办结人" readonly >
                <el-button slot="append" icon="el-icon-search"  @click="()=>this.$refs.receivingRef.show()" ></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" :xs="24">
            <el-form-item label="办结时间" prop="concludePersonTime">
              <el-date-picker clearable size="small" :disabled="disabled"
                  v-model="form.concludePersonTime"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择办结时间"
                  @change="changeAppointmentTime">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <TableSelect
      ref="receivingRef"
      :listColumns="receivingColumns"
      gridUrl="/system/user/list"
      @rowClick="receivingSelect"
      dialogWidth="780px"
      title="用户字典"
    />

  </div>
</template>

<script>
  import {getWorkOrder, addWorkOrder, updateWorkOrder,conCludeOrder} from "@/api/workorder/workOrder";

  export default {
    name: "ConcludeForm",
    dicts: ['coverage', 'degree_importance', 'service_type', 'complaints_type', 'project_identification', 'work_order_status',],
    data() {
      return {
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //是否禁用
        disabled: false,
        // 表单参数
        form: {},
        rules: {
          concludePersonName: [
            {required: true, message: "办结人不能为空", trigger: "blur"}
          ],
          concludePersonTime: [
            {required: true, message: "办结时间不能为空", trigger: "blur"}
          ],
        },
        receivingColumns:[
          {title:'用户名称',key:'nickName',type:'',isSearch:true},
          {title:'部门',key:'dept.deptName',type:'',isSearch:false},
          {title:'手机号码',key:'phonenumber',type:'',isSearch:true},
        ]
      };
    },
    created() {

    },
    methods: {
      show(option) {
        this.reset();
        getWorkOrder(option.id).then(response => {
          this.form = response.data;
          this.title = "办结";
          this.open = true;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.$emit("cancel")
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          communityId: null,
          floorId: null,
          unitId: null,
          roomId: null,
          no: null,
          orderType: null,
          charterMemberId: null,
          charterMemberName: null,
          charterTime: null,
          coverage:"10",
          degreeImportance: null,
          location: null,
          reflectPeopleId: null,
          reflectPeople: null,
          phoneNum: null,
          content: null,
          warrantyProject: null,
          repairType: null,
          complaintType: null,
          projectIdentification: null,
          imageAddress: null,
          receivingPersonId: null,
          concludePersonName: null,
          jointlyPersonId: null,
          jointlyPersonName: null,
          concludePersonTime: null,
          suspendPersonId: null,
          suspendPersonName: null,
          status: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null
        };
        this.resetForm("form");
      },
      receivingSelect(index,row){
        this.form.concludePersonId= row.userId;
        this.form.concludePersonName=row.nickName;
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            conCludeOrder(this.form).then(response => {
              this.msgSuccess("办结成功");
              this.cancel()
            });
          }
        });
      },
      changeAppointmentTime(v){
        if(v <= this.form.charterTime){
          this.msgWarning("办结时间必须小于发起时间。")
          this.form.concludePersonTime = null
        }
      }
    }
  };
</script>
